package com.fwtai.service.api;

import com.fwtai.api.ApiAreaDao;
import com.fwtai.tool.ToolClient;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.CompletableFuture;

/**
 * 区域位置
 * @作者 田应平
 * @版本 v1.0
 * @QQ号码 444141300
 * @创建日期 2021-07-20 10:40:21
 * @官网 <url>http://www.fwtai.com</url>
*/
@Service
public class ApiAreaService{

  @Resource
  private ApiAreaDao apiAreaDao;

  private final ThreadPoolTaskExecutor taskExecutor;

  public ApiAreaService(final ApiAreaDao apiAreaDao,final ThreadPoolTaskExecutor taskExecutor){
    this.apiAreaDao = apiAreaDao;
    this.taskExecutor = taskExecutor;
  }

  public String getAreaData(final String pid){
    return CompletableFuture.supplyAsync(()->{
      if(pid == null || pid.length() == 0){
        return ToolClient.queryJson(apiAreaDao.getAreaData(0));
      }
      return ToolClient.queryJson(apiAreaDao.getAreaData(Long.parseLong(pid)));
    },taskExecutor).join();
  }
}